package com.company3.students;

import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class mainlist {
    //启动
    public static void main(String[] args) {
        mainlist.getStart();
    }
    public static void getStart() {
        // 定一个存放学生对象的list
        List<student> listStudents = new LinkedList<>();
        // 获取输入
        Scanner sc = new Scanner(System.in);
        // 用于接收输入的值
        int age;
        int id;
        String name;
        while (true) {
            // 打印菜单
            System.out.println("1、增加学生信息；\n" + "2、查询学生信息；\n" + "3、删除学生信息；\n" + "4、修改学生信息；\n" + "5、打印所有学生；\n" + "0、退出；");
            // 获取输入的菜单选项
            int flag = sc.nextInt();
            switch (flag) {
                // 增加
                case 1:
                    System.out.println("输入id");
                    id = sc.nextInt();
                    System.out.println("输入姓名");
                    name = sc.next();
                    System.out.println("输入年龄");
                    age = sc.nextInt();
                    addstudent.addStudent(id, name, age, listStudents);
                    break;
                // 查找
                case 2:
                    System.out.println("输入id");
                    id = sc.nextInt();
                    student seachStudent = serchstudent.seachStudent(id, listStudents);
                    if (null == seachStudent) {
                        System.out.println("无对象");

                    } else {
                        System.out.println("搜索成功" + seachStudent);
                    }
                    break;
                // 删除
                case 3:
                    System.out.println("输入需要删除的id");
                    id = sc.nextInt();
                    delstudent.deleteStudent(id, listStudents);
                    break;
                // 改
                case 4:
                    System.out.println("输入要修改的id");
                    id = sc.nextInt();
                    student getStudent = serchstudent.seachStudent(id, listStudents);
                    // 如果查询结果为null，则退出，否则执行下面的修改操作
                    if (null == getStudent) {
                        System.out.println("无对象");
                        break;
                    }
                    System.out.println("输入id");
                    id = sc.nextInt();
                    System.out.println("输入姓名");
                    name = sc.next();
                    System.out.println("输入年龄");
                    age = sc.nextInt();
                    changestudent.changeStudent(id, name, age, getStudent);
                    break;
                // 打印
                case 5:
                    System.out.println("print");
                    printstudent.printStudents(listStudents);
                    break;
                // 退出
                case 0:
                    System.out.println("正在退出系统...");
                    break;
                default:
                    System.out.println("请重新选择");
                    break;
            }
            // 结束循环，退出系统
            if (0 == flag)
                break;
        }
        sc.close();
    }
}
